# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=turn-rs
pkgver=2.1.3
pkgrel=0
pkgdesc="A pure rust implemented turn server"
url="https://github.com/mycrl/turn-rs"
arch="all"
license="GPL-3.0-only"
makedepends="
	cargo
	cargo-auditable
	protobuf-dev
"
install="turn-rs.pre-install"
subpackages="
	$pkgname-openrc
	$pkgname-doc
	$pkgname-cli
	$pkgname-balance
"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/mycrl/turn-rs/archive/refs/tags/v$pkgver.tar.gz
	turn-rs.initd
	turn-rs.confd
"
options="net"

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm 755 target/release/turn-server "$pkgdir"/usr/bin/turn-server
	install -Dm 600 turn-server.toml "$pkgdir"/etc/turn-rs/turn-server.toml

	install -Dm 755 "$srcdir"/turn-rs.initd "$pkgdir"/etc/init.d/turn-rs
	install -Dm 644 "$srcdir"/turn-rs.confd "$pkgdir"/etc/conf.d/turn-rs

	install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

cli() {
	pkgdesc="$pkgdesc (command line monitoring tool)"
	install -Dm 755 "$builddir"/target/release/turn-cli "$subpkgdir"/usr/bin/turn-cli
}

balance() {
	pkgdesc="$pkgdesc (distributed load balancing service)"
	install -Dm 755 "$builddir"/target/release/turn-balance-server "$subpkgdir"/usr/bin/turn-balance-server
}

sha512sums="
01c5d978bbe70c018bf37e817a71b5e3bd030beba342f7567780feb837412bccd0fc56baeee1ff4abfb7ace092f71ca73be2b596091979110e3bbf72487508c1  turn-rs-2.1.3.tar.gz
0be3a81c5c9c13e2ba36a867282b3cae90e311d314c6e3f05855ce743fb2457ca12c0b7540e800bfe48a8e2129eb3acc970bc85b9b22dac70648b1637ccfb80f  turn-rs.initd
cc6b17c4efe13d0cc100e20c2d855cb5aa1cb4c7a65ccfa91757f0e667aac77ea020a17fdbcf67ef0de9a32c6133705e1bca2fe239d5ac19234d4de6f425e89e  turn-rs.confd
"
